//
// Created by jm on 2022/4/20.
//

#ifndef CAMSENSE_LIDAR_DRIVER_SRC_LIDAR_SCAN_H_
#define CAMSENSE_LIDAR_DRIVER_SRC_LIDAR_SCAN_H_
#include "camsense_lidar_driver/lidar.h"
class LidarScan {
 public:
  LidarScan() = default;
  ~LidarScan() = default;
  /// \brief 初始化雷达扫描类
  /// \param lidar_scan_callback　整圈数据回调函数
  /// \param port　串口地址
  /// \param baud　波特率
  /// \return　返回值:0，表示成功; 非零表示失败
  int Initialize(std::function<void(const std::vector<RangeData> &)> lidar_scan_callback,
                 const std::string &port,
                 unsigned int baud = 230400);
  /// \brief 释放雷达扫描类
  /// \return　返回值:0，表示成功; 非零表示失败
  int Release();
  void Run();
 private:
  void AddData(const std::vector<RangeData> &points);
  camsense::LidarDevice lidar_;
  bool init_flg_ = false;
  std::mutex mtx;
  std::thread send_thread_;

  std::condition_variable condition_variable_;
  float last_angle = 0;
  std::vector<RangeData> coll_data;
  std::vector<RangeData> pub_data;
  std::function<void(const std::vector<RangeData> &)> lidar_scan_callback_;
};

#endif //CAMSENSE_LIDAR_DRIVER_SRC_LIDAR_SCAN_H_
